package view; 


import util.TabItApplication;

import com.kkom1.tapeat.R;

import data_management.SettingData;
import android.app.Fragment;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

/**
 * <pre>
 * view 
 * SettingFragment.java
 *
 * �ㅻ챸 :
 * </pre>
 * 
 * @since : 2013. 8. 23.
 * @author : kwma
 * @version : v1.0
 */
public class SettingFragment extends Fragment {
	
	private SeekBar sensitive_bar;
	private TextView sample;
	private SeekBar rbar, gbar, bbar;
	private SettingData setting;

	private ToggleButton tb;
	private CheckBox cb;
	
/*	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		View v = inflater.inflate(R.layout.activity_settings, container);
		setting = SettingData.getInstance();
		setting.open();
		
		init(v);
		

		return v;
	}
	*/
	private void init(View v) {
		lockinit();
/*		findinit(v);
		eventinit();
		barinit();*/
	}

	
	private void lockinit(){
		tb.setChecked(setting.isLock_on());
		
		tb.setOnCheckedChangeListener(
				new CompoundButton.OnCheckedChangeListener(){
					public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			
						Log.d("isChecked:", ""+isChecked);
						
						setting.setLock_on(isChecked);
						setting.save();
						
						if(setting.isLock_on()){
							TabItApplication.getContext().startService(new Intent("com.kkom1.tapeat.services.lockservice"));
						}
						else {
							TabItApplication.getContext().stopService(new Intent("com.kkom1.tapeat.services.lockservice"));
						}
					}
				});
		
	}
	
/*	private void findinit(View v){
		//seekbars
		sensitive_bar = (SeekBar)v.findViewById(R.id.sensitivity_bar); 
		rbar = (SeekBar)v.findViewById(R.id.rbar);
		gbar = (SeekBar)v.findViewById(R.id.gbar); 
		bbar = (SeekBar)v.findViewById(R.id.bbar); 
		
		sample = (TextView)v.findViewById(R.id.sample);
		sample.setTextColor(Color.rgb(setting.r(), setting.g(), setting.b()));
		
		tb = (ToggleButton)v.findViewById(R.id.tog_lockon);
	}
	
	private void barinit(){
		sensitive_bar.setMax(setting.sens_limit());
		sensitive_bar.setProgress(setting.getSensitivity());
		rbar.setMax(256);
		rbar.setProgress(setting.r());
		gbar.setMax(256);
		gbar.setProgress(setting.g());
		bbar.setMax(256);
		bbar.setProgress(setting.b());
	}
	
	void eventinit(){
		sensitive_bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			public void onStopTrackingTouch(SeekBar seekBar) {}
			public void onStartTrackingTouch(SeekBar seekBar) {}
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				setting.setSensitivity(progress);
				setting.save();
			}
		});
		
		rbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			public void onStopTrackingTouch(SeekBar seekBar) {}
			public void onStartTrackingTouch(SeekBar seekBar) {}
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				setting.setr(progress);
				setting.save();
				sample.setTextColor(Color.rgb(setting.r(), setting.g(), setting.b()));
			}
		});
		gbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			public void onStopTrackingTouch(SeekBar seekBar) {}
			public void onStartTrackingTouch(SeekBar seekBar) {}
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				setting.setg(progress);
				setting.save();
				sample.setTextColor(Color.rgb(setting.r(), setting.g(), setting.b()));
			}
		});
		bbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			public void onStopTrackingTouch(SeekBar seekBar) {}
			public void onStartTrackingTouch(SeekBar seekBar) {}
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				setting.setb(progress);
				setting.save();
				sample.setTextColor(Color.rgb(setting.r(), setting.g(), setting.b()));
			}
		});
	}*/
}
